#ifndef __BASIC_H__
#define __BASIC_H__

#include <my_head.h>

/* 数据统一结构*/
/*登录数据*/
typedef struct{   
    char ID[128];
    char password[7];
    char flags; //成功 1 失败 0
}user_t;

/*查看环境数据*/
typedef struct{
	unsigned int temp;
	unsigned int hume;
	unsigned int lux;
	//unsigned char devstatus;// 0-7bit 0照明  1-2温控挡位(00==off 01==1挡 10==2挡 11=3挡) 3加湿 
} env_t;

typedef struct{
	char swlight;//照明开关 1开，0关
	char swfan;//风扇，空调 0关，其他是开
	char swmotor;//加湿器马达 1开，0关
}switch_t;

/*设置阈值数据*/
typedef struct{
	unsigned int tempup;
	unsigned int tempdown;
	unsigned int humeup;
	unsigned int humedown;
	unsigned int luxup;
	unsigned int luxdown;
} limitset_t;

typedef struct{
	//long msgtype;
    long long msgtype;
	char commd;
	user_t user;
	env_t envdata;
	switch_t switchset;
	limitset_t limitset;
	char deviceonline;//设备是否在线
	/*控制设备数据*/
	char devctrl;
} msg_t;

msg_t msg;

struct sockaddr_in server_addr;

/*采集到的数据缓冲变量*/
unsigned int conttemp;
unsigned int conthume;
unsigned int contlux;

/*用户设置的参考变量*/
unsigned int tempup;
unsigned int tempdown;
unsigned int humeup;
unsigned int humedown;
unsigned int luxup;
unsigned int luxdown;

int s_fd;

int switch_fd;
int tmp_hum_fd;
int light_fd;

//初始化网络
int tcp_net_init(const char *IP,const char *PORT);

/*根据用户设置的阈值维护恒定环境线程*/
void *hold_envthread(void *argv);

/*获取环境数据*/
void do_getenv(msg_t *msg);

/*设置阈值*/
void do_setlimit(msg_t *msg);

/*控制设备*/
void do_ctrldev(msg_t *msg);

/*打开驱动文件*/
int open_drive_fd(void);


#endif
